#include "pch.h"
#include "MenuGameState.h"
#include "Game.h"
#include "PlayGameState.h"

namespace GameStates
{
    
    MenuGameState::MenuGameState(Core::Game &game)
        : Core::GameState(game)
    {
    }
    
    void MenuGameState::Start()
    {
        titleScreen = game.resourceManager->GetSprite("titleScreen");
        playButton = game.resourceManager->GetSprite("playButton");
        quitButton = game.resourceManager->GetSprite("quitButton");
        cursor = game.resourceManager->GetSprite("cursor");

        menuItems.push_back(MenuItem("Play", playButton, 400, 300));
        menuItems.push_back(MenuItem("Quit", quitButton, 400, 400));
    }
    
    bool MenuGameState::Update()
    {
        float mouseX, mouseY;
        game.hge->Input_GetMousePos(&mouseX, &mouseY);
        bool hasClicked = game.hge->Input_GetKeyState(HGEK_LBUTTON);


		titleScreen->RenderEx(0, 0, 0, 1.741f, 1.959f);
        
        for(std::vector<MenuItem>::iterator iter = menuItems.begin(); iter != menuItems.end(); ++iter)
        {
            (*iter).TellMousePos(mouseX, mouseY);
            (*iter).Render();
            if(hasClicked && (*iter).IsColliding())
            {
                if((*iter).GetName() == "Play")
                {
                    game.PushState(new PlayGameState(game));
                }
                else if((*iter).GetName() == "Quit")
                {
                    return false;
                }
            }
        }
        
        cursor->Render(mouseX, mouseY);
        return true;
    }

    void MenuGameState::End()
    {
    }

}